package com.eagleyng.onlinefood.c.base;

import com.eagleyng.onlinefood.R;
import com.eagleyng.c.base.BaseActivity;
import com.eagleyng.onlinefood.m.IdataCallback;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

public abstract class MainActivity extends BaseActivity {
	private LinearLayout titleBar,bottomBar,mainBar;
	private TextView tvTitle;
	private Button btTitleLeft;
	private Handler handler = new Handler();
	private LinearLayout llTitlePb;
	private ProgressBar pbTitle;
	@Override
	public void onCreate(Bundle savedState) {
		super.onCreate(savedState);
		
		super.setContentView(R.layout.main);
		
		titleBar = (LinearLayout) findViewById(R.id.in_title_bar);
		btTitleLeft = (Button) findViewById(R.id.bt_title_left);
        tvTitle = (TextView) findViewById(R.id.tv_title);
        llTitlePb = (LinearLayout) findViewById(R.id.ll_title_pb);
        pbTitle = (ProgressBar) findViewById(R.id.pb_title);
        pbTitle.setVisibility(View.INVISIBLE);
        mainBar = (LinearLayout) findViewById(R.id.ll_main_bar);
        bottomBar = (LinearLayout) findViewById(R.id.in_bottom_bar);
        btTitleLeft.setVisibility(View.INVISIBLE);
        bottomBar.setVisibility(View.GONE);
	}
	
	@Override
	public void setContentView(int layoutResID) {
		LayoutInflater mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mainBar.addView(mInflater.inflate(layoutResID, null));
	}
	
	public void connectInvaliDate(final IdataCallback dataCall){
		pbTitle.setVisibility(View.VISIBLE);
		final Drawable dd = llTitlePb.getBackground();
		llTitlePb.setBackgroundDrawable(null);
		llTitlePb.setClickable(false);
		
		new Thread(new Runnable() {
			@Override
			public void run() {
				try {
					Thread.sleep(2000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				handler.post(new Runnable() {
					@Override
					public void run() {
						dataCall.callData(null);
						llTitlePb.setBackgroundDrawable(dd);
						pbTitle.setVisibility(View.INVISIBLE);
						llTitlePb.setClickable(true);
					}
				});
			}
		}).start();
	}
	
	public LinearLayout getLlTitlePb() {
		return llTitlePb;
	}

	public ProgressBar getPbTitle() {
		return pbTitle;
	}

	public TextView getTvTitle() {
		return tvTitle;
	}

	public Button getBtTitleLeft() {
		return btTitleLeft;
	}

	public LinearLayout getTitleBar() {
		return titleBar;
	}

	public LinearLayout getBottomBar() {
		return bottomBar;
	}

	public LinearLayout getMainBar() {
		return mainBar;
	}
	
}
